<?php

class ComercialDao extends Dao{

    public function injectDependencies() {

    }

    public function countNumberOfSubscriptionsByMonth($ItMonthNumber){
        $this->initConnection();
        $this->tMysqli->escape($ItMonthNumber);
        $StSql = TQuery::getSqlCountNumberOfSubscriptionsByMonth($ItMonthNumber);
        $this->tMysqli->exec($StSql);
        $numberOfSubscriptions = $this->tMysqli->result(0, 'NumberOfSubscriptions');
        $this->closeConnection();
        return is_numeric($numberOfSubscriptions) ? $numberOfSubscriptions : 0;
    }

    public function countNumberOfSubscriptionsByYear(){

        $this->initConnection();
        $StSql = TQuery::getSqlCountNumberOfSubscriptionsByYear();
        $this->tMysqli->exec($StSql);
        $Report = $this->tMysqli->fetchAll();
        $this->closeConnection();
        return $Report;
    }

    public function countNumberOfSubscriptionsByPeriod($InitialPeriod, $FinalPeriod){
        $this->initConnection();
        $this->tMysqli->escape($InitialPeriod);
        $this->tMysqli->escape($FinalPeriod);
        $StSql = TQuery::getSqlCountNumberOfSubscriptionsByPeriod($InitialPeriod, $FinalPeriod);
        $this->tMysqli->exec($StSql);
        $numberOfSubscriptions = $this->tMysqli->result(0, 'NumberOfSubscriptions');
        $this->closeConnection();
        return is_numeric($numberOfSubscriptions) ? $numberOfSubscriptions : 0;
    }

    public function countNumberOfCancelledCustomersByMonth($ItMonthNumber){
        $this->initConnection();
        $this->tMysqli->escape($ItMonthNumber);
        $StSql = TQuery::getSqlCountNumberOfCancelledCustomersByMonth($ItMonthNumber);
        $this->tMysqli->exec($StSql);
        $numberOfCancelledCustomers = $this->tMysqli->result(0, 'NumberOfCancelledCustomers');
        $this->closeConnection();
        return is_numeric($numberOfCancelledCustomers) ? $numberOfCancelledCustomers : 0;
    }

    public function countNumberOfCancelledCustomersByYear(){

        $this->initConnection();
        $StSql = TQuery::getSqlCountNumberOfCancelledCustomersByYear();
        $this->tMysqli->exec($StSql);
        $Report = $this->tMysqli->fetchAll();
        $this->closeConnection();
        return $Report;
    }

    public function countNumberOfCancelledCustomersByPeriod($InitialPeriod, $FinalPeriod){
        $this->initConnection();
        $this->tMysqli->escape($InitialPeriod);
        $this->tMysqli->escape($FinalPeriod);
        $StSql = TQuery::getSqlCountNumberOfCancelledCustomersByPeriod($InitialPeriod, $FinalPeriod);
        $this->tMysqli->exec($StSql);
        $numberOfCancelledCustomers = $this->tMysqli->result(0, 'NumberOfCancelledCustomers');
        $this->closeConnection();
        return is_numeric($numberOfCancelledCustomers) ? $numberOfCancelledCustomers : 0;
    }

}

?>
